package part1;

public class Part1 {

	/** 
	 * poweri - method to compute n to the power x using iteration
	 * 
	 * @require x >= 0
	 * @ensure  the value n to the power x is returned
	 */
	private static int poweri(int n, int x){
		int result = n;
		while (n>0){
			result = result * n;
		}
		return result;
	}

	/** 
	 * power - method to compute n to the power x using recursion
	 * 
	 * @require x >= 0
	 * @ensure  the value n to the power x is returned
	 */
	private static int power(int n, int x){
		int result = 1;
		if (x==0)
			return 1;
		result = n * power( n, x );
		return result;
	}

	public static void main(String[] args) {
		int a = 10;
		int m = 3;
		System.out.println(" a is " + a + " and m is " + m );
		int y = poweri( a , m );
		System.out.println("   therefore a^m is " + y);
		
		y = power( a, m );
		System.out.println("   using recursion, we see that a^m is " + y );
	}

}
